package org.example;

public class Main {
    public static void main(String[] args) {
        final long startTime = System.currentTimeMillis();
        int[] result = new int[3];
        for (int i = 0; i < 10; i++) {
            result = IntEq();
        }

        // 两个100万成员的数组中，相等的个数： 1 相等值： 2000001000  不相等的个数： 1000000 单次耗时(ms)： 2
        long costTime = System.currentTimeMillis() - startTime;
        System.out.println("两个100万成员的数组中" + " 不相等的个数：" + result[0] + " 相等的个数：" + result[1]+ " 相等值：" + result[2] + " 单次耗时(ms)：" + costTime / 10);
    }

    static int[] IntEq() {
        // 初始化一个100万成员的int类型数组，全部存储偶数，最后一个数组存储：
        final int num = 2000000;
        int coefficient = 1000;

        int[] arrEven = new int[num / 2 + 1];// 存储偶数100万+ 1个相等元素
        int[] arrOdd = new int[num / 2 + 1];// 存储偶数100万+ 1个相等元素

        int evenIndex = 0;
        int oddIndex = 0;

        for (int i = 1; i <= num; i++) {
            if (i % 2 == 0) {
                arrEven[evenIndex] = i * coefficient;
                evenIndex++;
            } else {
                arrOdd[oddIndex] = i * coefficient;
                oddIndex++;
            }
        }

        arrEven[evenIndex] = (num + 1) * coefficient;
        arrOdd[oddIndex] = (num + 1) * coefficient;

        int eqCounts = 0;
        int eqVal = 0;
        int neqCounts = 0;

        for (int i = 0; i <= num / 2; i++) {
            if (arrEven[i] == arrOdd[i]) {
                eqCounts++;
                eqVal = arrOdd[i];
            } else {
                neqCounts++;
            }
        }
        return new int[]{neqCounts, eqCounts, eqVal};
    }
}